<?php
class CgiClassModel extends Model{

	protected $_validate = array(
	array('name','require','CGI模块名称必填！',0,'',3),
	array('description','require','CGI模块描述必填！',0,'',3),
	array('owner','require','CGI模块负责人不可为空！',0,'',3),
	);

	protected $_auto = array(
	array('createtime','getDate',1,'callback'),
	);


	function getDate(){
		return date('Y-m-d H:i:s');
	}

	public function checkUser($username){
		$user = D('User');
		$data = $user->where("username='$username'")->select();
		if (count($data)>0){
			return true;
		}else {
			return false;
		}
	}

	/*
	 * 递归删除该模块下所有的目录和cgi
	 */
	public function deleteClass($rootid){
		$cgiItem = new CgiItemModel();
		$cgiItem->where("classid=$rootid")->delete();
		$ids = $this->where("parentid=$rootid")->field('id')->select();
		if (!empty($ids)){
			foreach ($ids as $id){
				$this->deleteClass($id['id']);
			}
		}
		$this->where("id=$rootid")->delete();
	}
	
	
}